/**
 * 
 */
package com.thor.palmmall.rest.communicate.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.chart.converter.APictureConverter;
import com.thor.palmmall.rest.common.AAttachment2Converter;
import com.thor.palmmall.rest.common.OperateInfoConverter;
import com.thor.palmmall.rest.communicate.ACommunicate;
import com.thor.palmmall.rest.tenant.converter.ALogosConverter;
import com.thor.palmmall.spi.communicate.SCommunicate;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class ACommunicateConverter implements Converter<SCommunicate, ACommunicate> {

  public static ACommunicateConverter getInstance() {
    if (instance == null)
      instance = new ACommunicateConverter();
    return instance;
  }

  private static ACommunicateConverter instance;

  private ACommunicateConverter() {
  }

  @Override
  public ACommunicate convert(SCommunicate source) {
    if (source == null) {
      return null;
    }
    ACommunicate target = new ACommunicate();
    target.setBrand(UCN.newInstance(source.getBrand()));
    target.setCommunicator(source.getCommunicator());
    target.setContactWay(source.getContactWay());
    target.setContent(source.getContent());
    target
        .setLastModifyInfo(OperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setCreateInfo(OperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target.setDate(source.getDate());
    target.setMethod(source.getMethod());
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setPositions(new ArrayList<UCN>());
    target.getPositions().addAll(source.getPositions());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setCounterpart(UCN.newInstance(source.getCounterpart()));
    target.setTheme(source.getTheme());
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCounterpartType(source.getCounterpartType());
    target.setLogos(ConverterUtil.convert(source.getLogos(), ALogosConverter.getInstance()));
    target
        .setPictures(ConverterUtil.convert(source.getPictures(), APictureConverter.getInstance()));
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), AAttachment2Converter.getInstance()));
    return target;
  }

}
